home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / AlexNeXTSTEPSource / Source / Chapter8_Prefs / Money / MoneyConverter.m < prev    next >
Text File  |  1995-06-12  |  1KB  |  64 lines

  1. /* Generated by Project Builder */
  2.  
  3. #import <appkit/appkit.h>
  4. #import "MoneyConverter.h"
  5. #import "PrefsController.h"
  6.  
  7. #define MAXIMUM 6
  8.  
  9. @implementation MoneyConverter
  10.  
  11. - convert:sender
  12. {
  13.     int index, loop;
  14.     unsigned int right,left = 10;
  15.     float entry, value, dollar_equiv;
  16.     id cell;
  17.     
  18.     // Array contains the conversion of rates
  19.     // of other currencies to dollars
  20.     static float rate[MAXIMUM] =
  21.         {1.00, 135.0, 0.50, 1.67, 6.00, 14.5};
  22.     
  23.     // Determine which field of the form
  24.     // was the last to be edited
  25.     index = [moneyForm selectedIndex];
  26.     
  27.     // Calculate equivalent of foreign currency
  28.     // at edited field to dollar equivalent
  29.     entry = [moneyForm floatValueAt:index];
  30.     dollar_equiv = entry / rate[index];
  31.  
  32.     // check if the Truncate default is set
  33.     // and then set the number of figures
  34.     // to the right of the decimal point
  35.     if ([prefsController shouldTruncate] == YES)    
  36.         right = 2;
  37.     else
  38.         right = 6;
  39.     // set floating point format for each
  40.     // formcell in the form
  41.     for (loop=0; loop < MAXIMUM; loop++)
  42.         {
  43.         // get each cell
  44.         cell = [moneyForm cellAt:loop :0];
  45.         [cell setFloatingPointFormat:NO
  46.             left:left right:right];
  47.         }
  48.  
  49.     for (loop = 0; loop < MAXIMUM; loop++)
  50.         {
  51.         // Calculate other currencies
  52.         // using look-up table
  53.         value = dollar_equiv * rate[loop];
  54.         // display value at appropriate field
  55.         [moneyForm setFloatValue:value at:loop];
  56.         }
  57.     // leave the last edited field as the
  58.     // selected text
  59.     [moneyForm selectTextAt:index];
  60.     return self;
  61. }
  62.  
  63. @end
  64.